package codetop.microsoft.T189;

/**
 * @Author: 18362
 * @Create: 2022-09-04 23:15:57 星期日
 */
class Solution {
    public void rotate(int[] nums, int k) {
        if (k % nums.length == 0)
            return;
        k %= nums.length;
        reverse(nums, 0, nums.length - k - 1);
        reverse(nums, nums.length - k, nums.length - 1);
        reverse(nums, 0, nums.length - 1);
    }

    private void reverse(int[] nums, int left, int right) {
        int i = left, j = right;
        while (i < j) {
            int t = nums[i];
            nums[i++] = nums[j];
            nums[j--] = t;
        }
    }
}